package qlsl.androiddesign.view.subview.activityview.peoplecenterbase;

import java.util.ArrayList;
import java.util.List;

import com.qlsl.androiddesign.kuaiwa.R;

import android.view.View;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ListView;
import qlsl.androiddesign.activity.baseactivity.BaseActivity;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * listView + 按钮页<br/>
 * 需要传入的键：<br/>
 * 传入的值类型： <br/>
 * 传入的值含义：<br/>
 * 是否必传 ：
 */
public abstract class ListWapBaseView<T, B extends BaseActivity> extends
		FunctionView<B> {

	protected ListView listView;

	protected List<T> list = new ArrayList<T>();

	/**
	 * 按钮设置文字
	 */
	protected Button send;

	public ListWapBaseView(B activity) {
		super(activity);
		setContentView(R.layout.common_list_wap_btn);
	}

	protected void initView(View view) {
		listView = findViewById(R.id.listView);
		send = findViewById(R.id.send);
	}

	protected void initData() {
		notifyDataSetChanged();
	}

	protected void initListener() {
	}

	public void onClick(View view) {

	}

	protected void resetList(List<T> list_result) {
		list.clear();
		list.addAll(list_result);
	}

	protected void notifyDataSetChanged() {
		BaseAdapter adapter = (BaseAdapter) listView.getAdapter();
		if (adapter == null) {
			adapter = getAdapter();
			listView.setAdapter(adapter);
		} else {
			adapter.notifyDataSetChanged();
		}
	}

	public abstract BaseAdapter getAdapter();

	/**
	 * 设置按钮文字
	 * 
	 * @param text
	 */
	public void setBtnText(String text) {
		send.setText("" + text);
	}
}
